import router from '@ohos.router';
import { StringUtils } from '../utils/StringUtils';

/**
 * 路由跳转工具类
 */
export class RouterHelper {
  /**
   * 跳转页面
   *
   * @param url 路由url
   */
  public static route(url: string, params: Object = {}) {
    router.pushUrl({
      url: url,
      params: params
    }, router.RouterMode.Standard, (err) => {
      if (err) {
        console.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`);
        return;
      }
      console.info('Invoke pushUrl succeeded.');
    });
  }

  /**
   * 跳转到图片预览界面
   */
  public static goImagePreview(url: string) {
    if (StringUtils.isNullOrEmpty(url)) {
      return;
    }
    RouterHelper.route(
      "pages/ImagePreviewPage",
      {
        imgUrl: url,
        imageIndex: 0
      });
  }
}